package com.example.ice.fittime.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.example.ice.fittime.entry.PraiseUser;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "PRAISE_USER".
*/
public class PraiseUserDao extends AbstractDao<PraiseUser, String> {

    public static final String TABLENAME = "PRAISE_USER";

    /**
     * Properties of entity PraiseUser.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property User_id = new Property(0, String.class, "user_id", true, "USER_ID");
        public final static Property Name = new Property(1, String.class, "name", false, "NAME");
        public final static Property Avatar_url = new Property(2, String.class, "avatar_url", false, "AVATAR_URL");
        public final static Property Recent_praise_user_s = new Property(3, String.class, "recent_praise_user_s", false, "RECENT_PRAISE_USER_S");
    }

    private Query<PraiseUser> userActivity_Recent_praise_userQuery;

    public PraiseUserDao(DaoConfig config) {
        super(config);
    }
    
    public PraiseUserDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"PRAISE_USER\" (" + //
                "\"USER_ID\" TEXT PRIMARY KEY NOT NULL ," + // 0: user_id
                "\"NAME\" TEXT," + // 1: name
                "\"AVATAR_URL\" TEXT," + // 2: avatar_url
                "\"RECENT_PRAISE_USER_S\" TEXT);"); // 3: recent_praise_user_s
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"PRAISE_USER\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, PraiseUser entity) {
        stmt.clearBindings();
 
        String user_id = entity.getUser_id();
        if (user_id != null) {
            stmt.bindString(1, user_id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        String avatar_url = entity.getAvatar_url();
        if (avatar_url != null) {
            stmt.bindString(3, avatar_url);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, PraiseUser entity) {
        stmt.clearBindings();
 
        String user_id = entity.getUser_id();
        if (user_id != null) {
            stmt.bindString(1, user_id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        String avatar_url = entity.getAvatar_url();
        if (avatar_url != null) {
            stmt.bindString(3, avatar_url);
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
    }    

    @Override
    public PraiseUser readEntity(Cursor cursor, int offset) {
        PraiseUser entity = new PraiseUser( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // user_id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // avatar_url
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, PraiseUser entity, int offset) {
        entity.setUser_id(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setAvatar_url(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
     }
    
    @Override
    protected final String updateKeyAfterInsert(PraiseUser entity, long rowId) {
        return entity.getUser_id();
    }
    
    @Override
    public String getKey(PraiseUser entity) {
        if(entity != null) {
            return entity.getUser_id();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(PraiseUser entity) {
        return entity.getUser_id() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "recent_praise_user" to-many relationship of UserActivity. */
    public List<PraiseUser> _queryUserActivity_Recent_praise_user(String recent_praise_user_s) {
        synchronized (this) {
            if (userActivity_Recent_praise_userQuery == null) {
                QueryBuilder<PraiseUser> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.Recent_praise_user_s.eq(null));
                userActivity_Recent_praise_userQuery = queryBuilder.build();
            }
        }
        Query<PraiseUser> query = userActivity_Recent_praise_userQuery.forCurrentThread();
        query.setParameter(0, recent_praise_user_s);
        return query.list();
    }

}
